perm filename PBLOCK.2[EAL,HE] blob sn#676474 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00007 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	{$NOMAIN	Block-parsing routines }
C00025 00003	{ Externally defined routines from elsewhere: }
C00028 00004	(* aux routines for parsing blocks: getDeclarations & checkBlkids *)
C00045 00005	function blockParse(st: statementp): boolean external
C00052 00006	function coblockParse(st: statementp): boolean external
C00056 00007	function endParse(st: statementp): boolean external
C00058 ENDMK
C⊗;
{$NOMAIN	Block-parsing routines }

const

  (* Constants from EDIT; need these for the constants section *)
  maxLines = 28;        (* smaller on the 11 than on the 10 *)
  maxPPLines = 18;
  maxBpts = 25;
  maxTBpts = 20;  	(* max could be exceeded by huge case stmnt *)
  listinglength = 2000; (* Length of Listingarray *)

type

  byte = 0..255;	(* doesn't really belong here, but... *)
  ascii = char; 
  atext = text;

{ Define all the pointer types here }

strngp = ↑strng;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;
reswordp = ↑resword;

(* This one is used whenever a pointer is needed for which the definition
 	is missing from this file; naturally, all pointers use the same space *)

dump = ↑integer;
cursorp = array[1..4] of integer;

(* datatype definitions *)

datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
	     frametype, eventtype, strngtype, labeltype, proctype, arraytype,
	     reftype, valtype, cmontype, nulltype, undeftype,
	     dimensiontype, mactype, macargtype, freevartype);

scalar = real;

cstring = packed array [1..10] of ascii;
c4str = packed array [1..4] of ascii;
c5str = packed array [1..5] of ascii;
c20str = packed array [1..20] of ascii;
linestr = packed array [1..130] of ascii;

strng = record
	  next: strngp;
	  ch: cstring;
	end;


(* statement definitions *)

stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
		fortype, iftype, whiletype, untiltype, casetype,
		calltype, returntype,
		printtype, prompttype, pausetype, aborttype, assigntype,
		signaltype, waittype, enabletype, disabletype, cmtype,
		affixtype, unfixtype,
		movetype, operatetype, opentype, closetype, centertype,
		stoptype, retrytype,
		requiretype, definetype, macrotype, commenttype, dimdeftype,
		setbasetype, wristtype, tovaltype, declaretype, emptytype);
		(* more??? *)

statement = packed record
		next, last: statementp; (* ↑ to lexical tokens? *)
		stlab: varidefp;
		exprs: nodep;	(* any expressions used by this statement *)
		nlines: integer;
		bpt: boolean;
		case stype: stmntypes of

    progtype:	    (pcode: statementp; errors: integer);
    blocktype,
    declaretype,
    endtype,
    coendtype:	    (bcode, bparent: statementp; blkid: identp;
			level, numvars: 0..255; variables: varidefp);
    coblocktype:    (threads: nodep; nthreads: integer; cblkid: identp);
    returntype:	    (retval, rproc: nodep);
    definetype:	    (macname,mpars: varidefp; macdef: tokenp);
    commenttype:    (len: integer; str: strngp; cbody: statementp);
    dimdeftype:	    (dimname: varidefp; dimexpr: nodep);
		end;


(* auxiliary definitions: variable, etc. *)

varidef = packed record
	    next,dnext: varidefp;
	    name: identp;
	    level: 0..255;	(* environment level *)
	    offset: 0..255;	(* environment offset *)
	    dtype: varidefp;	(* to hold the dimension info *)
	    tbits: 0..15;  (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
	    dbits: 0..15;	(* for use by debugger/interpreter *)
	    case vtype: datatypes of
  arraytype:  (a: nodep);
  proctype:   (p: nodep);
  labeltype,
  cmontype:   (s: statementp);
  mactype:    (mdef: statementp);
  macargtype: (marg: tokenp);
  pconstype:  (c: nodep);
  dimensiontype: (dim: nodep);
	  end;

(* definition of the ubiquitous NODE record *)

nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
		deprnode, viaptnode, apprnode, destnode, durnode,
		sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
		arrivalnode, departingnode,
		ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
		calcnode, arraydefnode, bnddefnode, bndvalnode,
		waitlistnode, procdefnode, tlistnode, dimnode, commentnode);

exprtypes =  (	svalop,					(* scalar operators *)
		sltop, sleop, seqop, sgeop, sgtop, sneop,	(* relations *)
		notop, orop, xorop, andop, eqvop,		(* logical *)
		saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
		sexpop, maxop, minop, intop, idivop, modop,
		sqrtop, logop, expop, timeop,			(* functions *)
		sinop, cosop, tanop, asinop, acosop, atan2op,	(* trig *)
		vdotop, vmagnop, tmagnop,
		vecop,					(* vector operators *)
		vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
		svmulop, vsmulop, vsdivop, tvmulop, wrtop,
		tposop, taxisop,
		transop,				(* trans operators *)
		tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
		vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
		ioop,					(* i/o operators *)
		queryop, inscalarop,
		specop,					(* special operators *)
		arefop, callop, grinchop, macroop, vmop, adcop, dacop,
		badop,
		addop, subop, negop, mulop, divop, absop); (* for parsing *)

leaftypes = pconstype..strngtype;

reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);

node = record
	next: nodep;
	case ntype: nodetypes of
    exprnode:	(op: exprtypes; arg1, arg2, arg3: nodep; elength: integer);
    leafnode:	(case ltype: leaftypes of
	varitype:  (vari: varidefp; vid: identp);
	pconstype: (cname: varidefp; pcval: nodep);
	svaltype:  (s: scalar; wid: integer);
	vectype:   (v: dump);
	transtype: (t: dump);
	strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
    listnode:	(lval: nodep);
    clistnode:	(cval: integer; stmnt: statementp; clast: nodep);
    colistnode:	(prev: nodep; cstmnt: statementp);
    errornode:	(eexpr: nodep);
    arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
    bnddefnode:	(lower, upper: nodep);
    bndvalnode:	(lb, ub, mult: integer);
    procdefnode:(ptype: datatypes; level: 0..255;
		    pname, paramlist: varidefp; body: statementp);
    tlistnode:	(tok: tokenp);
    dimnode:	(time, distance, angle, dforce: integer);
	end;

(* records for parser: ident, token, resword *)

ident = record
	    next: identp;
	    length: integer;
	    name: strngp;
	    predefined: varidefp;
	  end;


tokentypes = (reswdtype, identtype, constype, comnttype, delimtype, labeldeftype,
		macpartype);

constypes = svaltype..strngtype;

reswdtypes = (stmnttype, filtype, clsetype, decltype, optype, edittype);

filtypes = (abouttype,alongtype,attype,bytype,defertype,dotype,elsetype,
		errmodestype,fromtype,handtype,intype,nonrigidlytype,rigidlytype,
		sourcefiletype,steptype,thentype,totype,untltype,viatype,
		withtype,worldtype,zeroedtype,oftype,wheretype,nowaittype,
		ontype,offtype,ppsizetype,collecttype,alltype,lextype);

clsetypes = (approachtype,arrivaltype,departuretype,departingtype,durationtype,
		errortype,forcetype,forceframetype,forcewristtype,gathertype,
		nildeproachtype,nonullingtype,nullingtype,stiffnesstype,
		torquetype,velocitytype,wobbletype,
		cwtype,ccwtype,stopwaittimetype,angularvelocitytype,
		fxtype,fytype,fztype,mxtype,mytype,mztype,
		t1type,t2type,t3type,t4type,t5type,t6type,tbltype);

edittypes = (getcmd,savecmd,insertcmd,renamecmd,startcmd,gocmd,proceedcmd,
		stepcmd,sstepcmd,nstepcmd,gstepcmd,executecmd,setcmd,tracecmd,
		breakcmd,unbreakcmd,tbreakcmd,definecmd,markcmd,unmarkcmd,
		popcmd);

token = record
	  next: tokenp;
	  case ttype: tokentypes of
constype:   (cons: nodep);
comnttype:  (len: integer; str: strngp);
delimtype:  (ch: ascii);
reswdtype:  (case rtype: reswdtypes of
	stmnttype: (stmnt: stmntypes);
	filtype:   (filler: filtypes);
	clsetype:  (clause: clsetypes);
	decltype:  (decl: datatypes);
	optype:	   (op: exprtypes);
	edittype:  (ed: edittypes) );
identtype:  (id: identp);
labeldeftype: (lab: varidefp);
macpartype: (mpar: varidefp);
	end;


resword = record
	  next: reswordp;
	  length: integer;
	  name: strngp;
	  case rtype: reswdtypes of
	stmnttype:  (stmnt: stmntypes);
	filtype:    (filler: filtypes);
	clsetype:   (clause: clsetypes);
	decltype:   (decl: datatypes);
	optype:	    (op: exprtypes);
	edittype:  (ed: edittypes);
	  end;

(* Global variables *)

var 
	(* From ALMAIN *)
    b:boolean;		
    ch:ascii;
    ltime: real;

	(* From PARSE *)
    reswords: array [0..26] of reswordp;
    idents: array [0..26] of identp;
    macrostack: array [1..10] of tokenp;
    curmacstack: array [1..10] of varidefp;
    macrodepth: integer;
    curchar, maxchar, curline: integer;
    curBlock,newDeclarations: statementp;
    curProc: varidefp;
    pnode: nodep;
    nodim, distancedim, timedim, angledim,
      forcedim, torquedim, veldim, angveldim: varidefp;
    fvstiffdim, mvstiffdim: nodep;
    filedepth: integer;
    curpage: integer;
    sysVars,unVars: varidefp;
    errcount: integer;
    outerBlock: statementp;
    curVariable: varidefp;
    curMotion: statementp;
    endOk,coendOk: integer;
    moveLevel: integer;
    curErrhandler, curCmon: statementp;
    endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
    semiseen, shownline: boolean;
    eofError: boolean;
    inMove,inCoblock: boolean;
    curtoken: token;
    file1,file2,file3,file4,file5: atext;
    line: linestr;

	(* From INTERP *)
(*  curInt, activeInts, readQueue, allPdbs: pdbp;
    curEnv, sysEnv: envheaderp;
    clkQueue: nodep;
    allEvents: dump;
    STLevel: integer;	
    etime: integer;	
    curtime: integer; 	
    stime: integer;	
    msg: messagep;	
    inputp: integer;	
    debugLevel: integer;	*)
    d1: array[1..15] of dump;
    tSingleThreadMode: boolean;
    resched, running, escapeI, singleThreadMode: boolean;
    msgp: boolean;		(* flag set if any messages pending *)
    inputReady: boolean;
    inputLine: array [1..20] of ascii;

	(* From EDIT *)
    lines: array [1..maxLines] of dump; 
    ppLines: array [1..maxPPLines] of dump;	
    marks: array [1..20] of integer;
    cursorStack: array [1..15] of cursorp;
    bpts: array [1..maxBpts] of statementp;
    tbpts: array [1..maxTBpts] of statementp;
    debugPdbs: array [0..10] of dump;
    screenheight,dispHeight: integer;
    ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
    lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
    firstDline,topDline,botDline,firstLine,lastLine: integer;
    freeLines,oldLines: dump;
    findStmnt: statementp;
    nbpts,ntbpts: integer;
    eCurInt: dump;
    dProg: statementp;	
    smartTerminal: boolean; 
    setUp,setExpr,setCursor,dontPrint,outFilep,newVarOk,collect: boolean;
    eBackup: boolean;			
    eSingleThreadMode: boolean;	
    listing: packed array [0..listinglength] of ascii;
    lbuf: array [1..160] of ascii;
    ppBuf: array [1..100] of ascii;
    outFile: atext;
    eCurToken: token;			

	(* Various device & variable pointers *)
    speedfactor: dump;
    barm: dump;

	(* Various constant pointers *)
    xhat,yhat,zhat,nilvect: dump;
    niltrans: dump;
    bpark, ypark, gpark, rpark: dump;		(* arm park positions *)

{ Externally defined routines from elsewhere: }

	(* From ALLOC *)
function newNode: nodep;					external;
procedure relNode(n: nodep);					external;
function newIdent: identp;					external;
procedure relIdent(n: identp);					external;
function newVaridef: varidefp;					external;
function newStatement: statementp;				external;
procedure relStatement(n: statementp);				external;

	(* From FREE *)
procedure freStrng(st: strngp);					external;

	(* From PROOT *)
procedure errprnt;						external;
procedure getDelim(char: ascii);				external;
procedure getToken;						external;
function blStmntParse: statementp;				external;
function blExprParse: nodep;					external;

	(* From PAUX1 *)
function upperCase(c: ascii): ascii;				external;
function varLookup(id: identp): varidefp;			external;
function copyExpr(n: nodep; lcp: boolean): nodep;		external;

	(* From PAUX2 *)
function evalOrder(what,last: nodep; pcons: boolean): nodep;	external;
function matchdim(d1,d2: nodep; exactp: boolean): boolean;	external;

	(* Display-related Routines *)
procedure ppLine; 						external;
procedure ppOutNow; 						external;
procedure ppChar(ch: ascii); 					external;
procedure pp5(ch: c5str; length: integer); 			external;
procedure pp10(ch: cstring; length: integer); 			external;
procedure pp10L(ch: cstring; length: integer);			external;
procedure pp20(ch: c20str; length: integer); 			external;
procedure pp20L(ch: c20str; length: integer); 			external;
procedure ppInt(i: integer); 					external;
procedure ppReal(r: real); 					external;
procedure ppStrng(length: integer; s: strngp); 			external;


procedure pBlGet; external;
procedure pBlGet; begin end;
(* aux routines for parsing blocks: getDeclarations & checkBlkids *)

function getDeclarations(pdef: boolean; lev: integer;
			 var vo: varidefp; var numvars: integer): varidefp; external;
function getDeclarations;
 var vhdr,va,vp,vdim: varidefp; off,tb,i: integer; d: datatypes;
     endlist,b: boolean; no,n: nodep; idname: identp;

 function declarationp: boolean;
  var b: boolean; v: varidefp;
  begin
  b := false;
  getToken;
  with curToken do
   if ttype = reswdtype then
     begin
     if rtype = decltype then b := true
      else if (rtype = optype) and ((op = vmakeop) or (op = vsaxwrop) or
				   (op = tmakeop) or (op = fmakeop)) then
       begin
       b := true;
       rtype := decltype;
       if op = vmakeop then decl := vectype
	else if op = vsaxwrop then decl := rottype
	else if op = tmakeop then decl := transtype else decl := frametype;
       end
      else if ((rtype = clsetype) and
	       ((clause = forcetype) or (clause = torquetype) or
	       (clause = angularvelocitytype) or (clause = velocitytype))) then
       begin
       b := true;
       ttype := identtype;
       if clause = forcetype then id := forcedim↑.name
	else if clause = torquetype then id := torquedim↑.name
	else if clause = velocitytype then id := veldim↑.name
	else id := angveldim↑.name;
       end
     end
    else if ttype = identtype then
     begin
     v := varLookup(id);
     if v <> nil then b := v↑.vtype = dimensiontype else b := false;
     end;
  if not b then backup := true;
  declarationp := b;
  end;

 begin
 numvars := 0;
 if vo = nil then off := 0 else off := vo↑.offset + 1;
 vhdr := nil;
 if declarationp then			(* any declarations? *)
  with curToken do
   begin
   flushcomments := true;		(* don't allow comments here *)
   b := true;
   if pdef then
     if (ttype = reswdtype) and (rtype = decltype) and
	((decl = reftype) or (decl = valtype)) then
       begin			(* "reference" or "value" procedure args *)
       if decl = valtype then tb := 0 else tb := 4;
       b := declarationp;		(* get dimension or base type *)
       end
     else tb := 4		(* pass by "reference" is the default *)
    else tb := 0;
   if (ttype = identtype) and b then
     begin				(* deal with dimension info *)
     vdim := varLookup(id);		(* save it for later *)
     b := declarationp;			(* get base datatype *)
     end
    else vdim := nil;
   if (not b) or (ttype <> reswdtype) or (rtype <> decltype) or
      (decl > arraytype) then
     begin			(* not a valid basic datatype *)
     pp20L('Need a basic datatyp',20); pp20('e here - flushing ti',20);
     pp20('l next semicolon    ',16);
     errprnt;
     while (ttype <> delimtype) or (ch <> ';') do getToken; (* flush tokens *)
     end
    else
     begin
     if decl <> arraytype then d := decl
      else
       begin
       d := undeftype;				(* define it later *)
       backup := true;
       pp20L('Need to specify base',20); pp20(' type of array - wil',20);
       pp20('l try to define it l',20); pp5('ater ',4);
       errprnt;
       end;
     if d <> proctype then getToken; (* is this really an array or procedure? *)
     if (ttype = reswdtype) and (rtype = decltype) and (decl = proctype) then
       begin			(* procedure definition *)
       getToken;			(* get the procedure's name *)
       if ttype <> identtype then
	 begin				(* garbage *)
	 pp20L('Expecting an identif',20); pp10('ier here  ',8);
	 errprnt;
	 backup := true;
	 idname := nil;
	 end
	else idname := id;
       vp := newVaridef;
       if vhdr = nil then
	 begin
	 vhdr := vp;
	 if (vo = nil) and (not pdef) then curBlock↑.variables := vhdr;
	 end;
       if vo <> nil then
	with vo↑ do next := vp;		(* add to list *)
       vo := vp;
       vp := curProc;			(* save any outer procedure *)
       with vo↑ do
	begin
	next := nil;
	dnext := vp;		(* hack to stack any nested proc defs *)
	name := idname;
	level := lev;
	offset := off;
	off := off + 1;
	numvars := numvars + 1;
	tbits := 2;
	if d = proctype then vtype := nulltype else vtype := d;
	dtype := vdim;
	n := newNode;
	p := n;
	end;
       with n↑ do
	begin
	ntype := procdefnode;
	ptype := vo↑.vtype;
	level := lev + 1;
	pname := vo;
	getToken;		(* see if procedure has any parameters *)
	paramlist := nil;
	if (ttype = delimtype) and (ch = '(') then	(* yup - get 'em *)
	  begin
	  va := nil;
	  repeat
	   vdim := getDeclarations(true,level,va,i);
	   if paramlist = nil then paramlist := vdim;
	  until i = 0;
	  flushcomments := true;
	  getDelim(')');			(* look for closing ")" *)
	  end
	 else backup := true;
	getDelim(';');				(* get separating ";" *)
	curProc := vo;
	body := blStmntParse;		(* get the body of the procedure *)
	body↑.next := newStatement;	(* append a return, just in case *)
	with body↑.next↑ do
	 begin
	 stype := returntype;
	 retval := nil;
	 exprs := nil;
	 last := n↑.body;
	 rproc := n;
	 end;
	end;
       curProc := vp;			(* restore outer procedure, if any *)
       if not semiseen then getDelim(';');
       end
      else
       begin
       if (ttype = reswdtype) and (rtype = decltype) and (decl = arraytype) then
	 begin
	 tb := tb + 1;			(* we've got an array specification *)
	 va := nil;	(* for list of arrays sharing common bounds list *)
	 if pdef and (tb = 1) then
	   begin
	   tb := 5;
	   pp20L('Can''t pass arrays by',20); pp20(' value - changing to',20);
	   pp10(' reference',10);
	   errprnt;
	   end
	 end
	else
	 begin
	 backup := true;
	 if pdef and (tb = 0) and (d = eventtype) then
	   begin
	   tb := 4;
	   pp20L('Can''t pass events by',20); pp20(' value - changing to',20);
	   pp10(' reference',10);
	   errprnt;
	   end
	 end;
       if vdim <> nil then	(* check that dimension applies to base type *)
	 begin
	 b := false;
	 if (d = rottype) and not matchdim(vdim↑.dim,angledim↑.dim,true) then
	   begin
	   b := true;
	   pp20L('Rotations must be of',20); pp20(' dimension ANGLE    ',16);
	   end
	  else if (d = frametype) and
		  not matchdim(vdim↑.dim,distancedim↑.dim,true) then
	   begin
	   b := true;
	   pp20L('Frames must be of di',20); pp20('mension DISTANCE    ',16);
	   end;
	 if b then
	   begin
	   errprnt;
	   vdim := nil;
	   end
	 end;
       repeat
	endlist := true;		(* assume this is last one *)
	getToken;			(* declare the new variables *)
	if ttype <> identtype then
	  begin				(* garbage *)
	  pp20L('Expecting an identif',20); pp10('ier here  ',8);
	  errprnt;
	  backup := true;
	  end
	 else
	  begin
	  vp := newVaridef;
	  if vhdr = nil then
	    begin
	    vhdr := vp;
	    if (vo = nil) and (not pdef) then curBlock↑.variables := vhdr;
	    end;
	  if vo <> nil then
	   with vo↑ do next := vp;	(* add to list *)
	  vo := vp;
	  if id↑.predefined <> nil then
	   if id↑.predefined↑.vtype = pconstype then
	    begin
	    pp20L('Redefining predeclar',20); pp20('ed constant - not a ',20);
	    pp10('good idea ',9);
	    errprnt;
	    end;
	  with vp↑ do
	   begin
	   next := nil;
	   dnext := nil;
	   name := id;
	   level := lev;
	   offset := off;
	   off := off + 1;
	   numvars := numvars + 1;
	   tbits := tb;
	   vtype := d;
	   dtype := vdim;
	   if d = labeltype then s := nil;
	   end;
	  if odd(tb) then
	    begin			(* look for array bounds *)
	    getToken;			(* looking for a "[" *)
	    if (ttype <> delimtype) or (ch <> '[') then
	      begin			(* not yet *)
	      backup := true;
	      vp↑.a := nil;		(* no bounds info yet *)
	      if va = nil then va := vp;  (* so we can fill things in later *)
	      if (ttype = delimtype) and (ch = ';') then
		begin			(* we aren't going to get one *)
		va := nil;
		if not pdef then
		 begin
		 pp20L('Expecting an array b',20); pp20('ounds list here     ',15);
		 errprnt;
		 end
		end
	      end
	     else
	      begin			(* got one *)
	      vp↑.a := newNode;
	      vp↑.a↑.ntype := arraydefnode;
	      vp↑.a↑.combnds := false;
	      no := nil;
	      i := 0;
	      repeat
	       n := newNode;
	       i := i + 1;
	       with n↑ do
		begin
		ntype := bnddefnode;
		next := nil;
		lower := blExprParse;	(* get lower bound definition *)
		getDelim(':');		(* looking for separating ":" *)
		upper := blExprParse;	(* get upper bound definition *)
		getToken;	(* looking for final "]" or separating "," *)
		if (ttype <> delimtype) or ((ch <> ',') and (ch <> ']')) then
		  begin
		  pp20L('Expecting a "," or "',20); pp10(']" here   ',7);
		  errprnt;
		  backup := true;
		  end;
		if no = nil then vp↑.a↑.bounds := n else no↑.next := n;
		no := n;
		end
	       until ((ttype = delimtype) and ((ch = ']') or (ch = ';'))) or
		     (ttype = reswdtype);
	      vp↑.a↑.numdims := i;
	      while va <> nil do		(* now we can fill things in *)
		begin
		va↑.a := copyexpr(vp↑.a,false);	(* copy bounds info *)
		va := va↑.next;
		if va↑.next = nil then va := nil; (* we already got this one *)
		end
	      end
	    end;
	  getToken;			(* looking for "," or ";" or ")" *)
	  if ttype = delimtype then
	    begin
	    if ch = ',' then endlist := false	(* more to get *)
	     else if pdef and (ch = ')') then backup := true
	     else if ch <> ';' then
	      begin
	      pp20L('Expecting a "," or "',20); pp10(';" here   ',7);
	      errprnt;
	      end
	    end
	   else
	    begin
	    backup := true;
	    pp20L('Inserting missing " ',19);
	    if ttype = identtype then	(* user defined dimension type? *)
	      begin
	      vp := varLookup(id);
	      if vp = nil then endlist := false
		else if vp↑.vtype <> dimensiontype then endlist := false;
	      end;
	    if endlist then pp5(';"   ',2)
	     else pp5(',"   ',2);
	    errprnt;
	    end
	  end
	until endlist;
       end
     end;
   flushcomments := false;		(* comments are ok again *)
   end;
 getDeclarations := vhdr;
 end;

procedure checkblkids(id1,id2: identp); external;
procedure checkblkids;
 var c1,c2: ascii; i,j,len: integer; b: boolean; s1,s2: strngp;
 begin
 if (id1 <> nil) and (id2 <> nil) then
   begin
   len := id1↑.length;
   b := len = id2↑.length;  (* make sure both strings are the same length *)
   s1 := id1↑.name;
   s2 := id2↑.name;
   i := 0;
   j := 1;
   while b and (i < len) do
    begin
    c1 := upperCase(s1↑.ch[j]);
    c2 := upperCase(s2↑.ch[j]);
    if c1 <> c2 then b := false
     else
      begin
      i := i + 1;
      if j < 10 then j := j + 1
       else begin j := 1; s1 := s1↑.next; s2 := s2↑.next end;
      end;
    end;
   if not b then
     begin
     pp20L('Block ids do not mat',20); pp5('ch   ',2);
     errprnt;
     end;
   end;
 end;

function blockParse(st: statementp): boolean; external;
function blockParse;
 var b,bs: boolean; so,sp: statementp; bid: identp;
     oldVariable,v,vhdr,vo: varidefp; i: integer; lexp: nodep;     
 begin			(* block statement *)
 b := false;		(* no way(?) we can lose here *)

 flushcomments := false;	(* in trouble if comment before id, but... *)
 getToken;				(* any block id? *)
 with curToken do
  begin
  st↑.blkid := nil;
  if ttype = constype then
    begin
    if cons↑.ltype = strngtype then	(* yup - grab the id string *)
      begin
      bid := newIdent;
      bid↑.length := cons↑.length;
      bid↑.name := cons↑.str;
      st↑.blkid := bid;
      end
     else
      begin
      pp20L('Need a string here  ',18);
      errprnt;
      end;
    relNode(cons);
    end
   else backup := true;
  end;

 with st↑ do
  begin
  if curBlock = nil then level := 1 else level := curBlock↑.level + 1;
  if curProc <> nil then	(* may need to correct if outer block of proc *)
    if curProc↑.p↑.level = level then level := level + 1;
  bparent := curBlock;
  bcode := nil;
  end;
 curBlock := st;
 if outerBlock = nil then outerBlock := st;
 oldVariable := curVariable;
 curVariable := nil;
 vhdr := nil;
 st↑.variables := nil;
 so := nil;
 bs := true;
 while bs do
  begin
  flushcomments := false;		(* comments are ok here *)
  vhdr := getDeclarations(false,st↑.level,curVariable,i); (* get any block vars *)
  if i > 0 then
    begin			(* make a decl stmnt for data type *)
    vo := vhdr;
    v := vhdr↑.next;
    while v <> nil do begin vo↑.dnext := v; vo := v; v := v↑.next end;
    sp := newStatement;
    with sp↑ do
      begin
      stype := declaretype;
      numvars := i;
      variables := vhdr;
      end;
    if so = nil then	(* may have declared some undefined variables *)
      begin so := st↑.bcode;
	    if so <> nil then while so↑.next <> nil do so := so↑.next end;
    if so = nil then begin sp↑.last := st; st↑.bcode := sp end
     else begin so↑.next := sp; sp↑.last := so end;
    so := sp;
    end
   else
    begin
    endOk := 1;
    sp := blStmntParse;			(* get the next statement *)
    if sp↑.stype = emptytype then relStatement(sp)	(* flush bad ones *)
     else
      begin
      if so = nil then	(* may have declared some undefined variables *)
	begin so := st↑.bcode;
	      if so <> nil then while so↑.next <> nil do so := so↑.next end;
      if so = nil then begin sp↑.last := st; st↑.bcode := sp end
       else begin so↑.next := sp; sp↑.last := so end;
      so := sp;
      if sp↑.stype = endtype then	(* we're all done *)
	begin
	bs := false;
	sp↑.bparent := st;
	sp↑.next := nil;
	checkblkids(st↑.blkid,sp↑.blkid);
	end
       else
	if not semiseen and (sp↑.stype <> commenttype) then
	  begin				(* look for the separating ";" *)
	  getToken;
	  with curToken do
	   if (ttype <> delimtype) or (ch <> ';') then  (* not there *)
	    begin
	    backup := true;
	    if not ((ttype = reswdtype) and (rtype = stmnttype) and
		    ((stmnt = endtype) or (stmnt = commenttype))) then
	     begin
	     pp20('Inserting missing se',20); pp10('micolon   ',7);
	     errprnt;
	     end;
	    end;
	  end;
      end;
    end;
  end;

 v := st↑.variables;	(* need to pop block's variables from symbol table *)
 i := 0;		(*  we can count number of them while we're at it too *)
 lexp := nil;
 while v <> nil do
  begin
  if v↑.tbits = 1 then lexp := evalOrder(v↑.a↑.bounds,lexp,false);
(* *** confirm that all labels that should be labelling cmons actually are *** *)
  i := i + 1;
  v := v↑.next;
  end;
 st↑.numvars := i;
 st↑.exprs := lexp;

 curVariable := oldVariable;
 if curVariable <> nil then  (* in case any undefined variables were declared *)
  while curVariable↑.next <> nil do curVariable := curVariable↑.next;
 curBlock := st↑.bparent;
 blockParse := false;		(* no way(?) we can lose here *)
 end;

function coblockParse(st: statementp): boolean; external;
function coblockParse;
 var b,bs,oldInCoblock: boolean; no,np: nodep; sp: statementp; bid: identp;
     i: integer;
 begin			(* coblock statement *)
 b := false;		(* no way(?) we can lose here *)
 getToken;		(* any block id? *)
 with curToken do
  begin
  st↑.cblkid := nil;
  if ttype = constype then
    begin
    if cons↑.ltype = strngtype then	(* yup - grab the id string *)
      begin
      bid := newIdent;
      bid↑.length := cons↑.length;
      bid↑.name := cons↑.str;
      st↑.cblkid := bid;
      end
     else
      begin
      pp20L('Need a string here  ',18);
      errprnt;
      end;
    relNode(cons);
    end
   else backup := true;
  end;

 i := 0;
 st↑.threads := nil;
 oldInCoblock := inCoblock;
 inCoblock := true;			(* can't have any returns in threads *)
 no := nil;
 bs := true;
 while bs do
  begin
  flushcomments := false;		(* comments are ok here *)
  coendOk := 1;
  sp := blStmntParse;			(* get the next statement *)
  sp↑.last := st;			(* set up a back pointer *)
  if sp↑.stype = emptytype then relStatement(sp)	(* flush bad ones *)
   else
    if sp↑.stype = coendtype then	(* we're all done *)
      begin
      bs := false;
      st↑.nthreads := i;
      sp↑.bparent := st;
      sp↑.next := nil;
      checkblkids(st↑.cblkid,sp↑.blkid);
      np := st↑.threads;  (* now have all threads point to the coend stmnt *)
      while np <> nil do
	begin
	np↑.cstmnt↑.next := sp;
        np := np↑.next
	end;
      end
     else
      begin
      if sp↑.stype <> commenttype then i := i + 1;
      np := newNode;
      np↑.ntype := colistnode;
      np↑.cstmnt := sp;
      np↑.next := nil;
      if no = nil then begin np↑.prev := nil; st↑.threads := np end
       else begin no↑.next := np; np↑.prev := no end;
      no := np;
      if not semiseen then
	begin
	getToken;			(* look for the separating ";" *)
	with curToken do
	 if (ttype <> delimtype) or (ch <> ';') then  (* not there *)
	  begin
	  backup := true;
	  if not ((sp↑.stype = commenttype) or
		 ((ttype = reswdtype) and (rtype = stmnttype) and
		  ((stmnt = coendtype) or (stmnt = commenttype)))) then
	   begin
	   pp20L('Inserting missing se',20); pp10('micolon   ',7);
	   errprnt;
	   end;
	  end;
	end;
      end;
  end;
 inCoblock := oldInCoblock;
 coblockParse := b;
 end;

function endParse(st: statementp): boolean; external;
function endParse;
 var bid: identp; b: boolean;
 begin					(* end or coend statement *)
 st↑.blkid := nil;
 if curchar + 2 < maxchar then
   begin
   getToken;	(* any block id? *)
   with curToken do
    begin
    if ttype = constype then
      begin
      if cons↑.ltype = strngtype then	(* yup - grab the id string *)
	begin
	bid := newIdent;
	bid↑.length := cons↑.length;
	bid↑.name := cons↑.str;
	st↑.blkid := bid;
	end
       else
	begin
	pp20L('Need a string here  ',18);
	errprnt;
	end;
      relNode(cons);
      end
     else backup := true;
    end;
  end;
 if st↑.stype = endtype then b := endOk < 0
  else b := coendOk < 0;
 if b then
   begin
   pp20L('Can''t have an END/CO',20); pp10('END here  ',8); ppLine;
   errprnt;
   if st↑.blkid <> nil then
     begin freStrng(st↑.blkid↑.name); relIdent(st↑.blkid) end;
   end;
 endParse := b;
 end;